﻿using CampWeek5__Book_Project_.Data.Model;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations; //used for AddOrUpdate()
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CampWeek5__Book_Project_.Data.Migrations
{
    public static class Seeder
    {
        //UserIds
        private static string Test;

        private static string Admin;
        private static string Sally;
        private static string Vanessa;
        private static string Jimmy;
        private static string Joe;
        private static string Bob;
        private static string Ralph;

        public static void Seed(ApplicationDbContext db,
            bool roles = true,
            bool users = true,
            bool auth = true,
            bool tags = true,
            bool author_tags = true,
            bool book_tags = true,
            bool books = true,
            bool ratings = true)
        {
            if (roles) SeedRoles(db);
            if (users) SeedUsers(db);

            //after seeding users, grab their ids
            Test = db.Users.FirstOrDefault(x => x.UserName == "test@test.com").Id;
            Admin = db.Users.FirstOrDefault(x => x.UserName == "admin@test.com").Id;
            Vanessa = db.Users.FirstOrDefault(x => x.UserName == "vanessa@test.com").Id;
            Bob = db.Users.FirstOrDefault(x => x.UserName == "bob@test.com").Id;
            Jimmy = db.Users.FirstOrDefault(x => x.UserName == "jimmy@test.com").Id;
            Sally = db.Users.FirstOrDefault(x => x.UserName == "sally@test.com").Id;
            Ralph = db.Users.FirstOrDefault(x => x.UserName == "ralph@test.com").Id;
            Joe = db.Users.FirstOrDefault(x => x.UserName == "joe@test.com").Id;

            if (auth) SeedAuthors(db);
            if (books) SeedBooks(db);
            if (tags) SeedTags(db);
            if (author_tags) SeedAuthorTags(db);
            if (book_tags) SeedBookTags(db);
            if (ratings) SeedRatings(db);
        }

        private static void SeedRoles(ApplicationDbContext db)
        {
            var store = new RoleStore<IdentityRole>(db);
            var manager = new RoleManager<IdentityRole>(store);

            if (!manager.RoleExists(Roles.USER))
            {
                manager.Create(new IdentityRole() { Name = Roles.USER });
            }
            if (!manager.RoleExists(Roles.ADMIN))
            {
                manager.Create(new IdentityRole() { Name = Roles.ADMIN });
            }
        }

        private static void SeedUsers(ApplicationDbContext db)
        {
            var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(db));

            if (!db.Users.Any(x => x.UserName == "test@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "test@test.com",
                    UserName = "test@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "admin@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "admin@test.com",
                    UserName = "admin@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.ADMIN);
            }
            if (!db.Users.Any(x => x.UserName == "vanessa@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "vanessa@test.com",
                    UserName = "vanessa@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "bob@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "bob@test.com",
                    UserName = "bob@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "ralph@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "ralph@test.com",
                    UserName = "ralph@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "jimmy@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "jimmy@test.com",
                    UserName = "jimmy@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "joe@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "joe@test.com",
                    UserName = "joe@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
            if (!db.Users.Any(x => x.UserName == "sally@test.com"))
            {
                ApplicationUser user = new ApplicationUser()
                {
                    Email = "sally@test.com",
                    UserName = "sally@test.com"
                };
                manager.Create(user, "123123");
                manager.AddToRole(user.Id, Roles.USER);
            }
        }

        private static void SeedAuthors(ApplicationDbContext db)
        {
            db.Authors.AddOrUpdate(
               a => a.Id,
               new Author { Id = 1, AuthorName = "David Gonzalez", AuthorBio = "David Gonzales is widely considered to be the foremost expert on Lebron James.", AuthorCountry = "USA", DateOfBirth = Convert.ToDateTime("9/3/1990"), AuthorImg = "https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSs_4PTiAd8Or75E8W3iBov0Q9MiFxqxXdghFZEtI-4z0JHlsRk", DateOfDeath = null, TimesViewed = 12310 },
               new Author { AuthorName = "Bill Shakespeare", AuthorBio = "William Shakespeare (1564-1616). English poet and playwright –  Shakespeare is widely considered to be  the greatest writer in the English language. He wrote 38 plays and 154 sonnets.", AuthorCountry = "England", DateOfBirth = Convert.ToDateTime("4/23/1616"), DateOfDeath = Convert.ToDateTime("6/27/1676"), AuthorImg = "http://i.telegraph.co.uk/multimedia/archive/02192/bardtimes_2192865b.jpg", Id = 2, TimesViewed = 123 },
                //Seeder added
               new Author { AuthorName = "Stephen King", AuthorBio = "Has a rich, horrific imagination. He has sold over 350 million books, many of which have been adapted to films, television shows, and comic books. He has published 54 novels and nearly 200 short stories.", AuthorCountry = "USA", DateOfBirth = Convert.ToDateTime("4/23/1956"), DateOfDeath = Convert.ToDateTime("6/27/1676"), AuthorImg = "http://images.boomsbeat.com/data/images/full/197275/stephen-king.jpg", Id = 3, TimesViewed = 123 },
               new Author { AuthorName = "Daniel James Brown", AuthorBio = "Specializes in bringing history to life.", AuthorCountry = "USA", DateOfBirth = Convert.ToDateTime("1/2/1964"), DateOfDeath = Convert.ToDateTime("6/27/1676"), AuthorImg = "https://pbs.twimg.com/profile_images/700196328/djb_400x400.jpg", Id = 4, TimesViewed = 123 },
               new Author { AuthorName = "Judy Blume", AuthorBio = "Specializes in writing for children and women.", AuthorCountry = "USA", DateOfBirth = Convert.ToDateTime("5/5/1966"), DateOfDeath = null, AuthorImg = "http://ccbc.education.wisc.edu/_images/people/blume.jpg", Id = 5, TimesViewed = 123 },
               new Author { AuthorName = "David McCullough", AuthorBio = "Two-time Pulitzer Prize winner.", AuthorCountry = "USA", DateOfBirth = Convert.ToDateTime("9/26/1929"), DateOfDeath = null, AuthorImg = "http://blog.wellreadlife.com/.a/6a00e54f8eed218833012876079273970c-pi", Id = 6, TimesViewed = 123 }
               );
        }

        private static void SeedBooks(ApplicationDbContext db)
        {
            db.Books.AddOrUpdate(
                b => b.Id,
                //David's Books
                new Book { Id = 1, AuthorId = 1, BookImg = "https://s-media-cache-ak0.pinimg.com/736x/17/08/1a/17081a2e5fee5339cbe32a9f724fd2b5.jpg", ISBN = 1425, PubDate = Convert.ToDateTime("6/7/1969"), Summary = "How LBJ lost in the finals", Title = "Peasant James", TimesViewed = 786 },
                new Book { Id = 2, AuthorId = 1, BookImg = "http://justforthefunzies.com/wp-content/uploads/2013/09/ron-swanson.jpg", ISBN = 8945, PubDate = Convert.ToDateTime("4/7/2014"), Summary = "How to be a man", Title = "Manhood", TimesViewed = 432 },
                //Bill's books
                new Book { Id = 3, AuthorId = 2, BookImg = "http://d28hgpri8am2if.cloudfront.net/book_images/cvr9781451621709_9781451621709_hr.jpg", ISBN = 5472, PubDate = Convert.ToDateTime("1/1/1597"), Summary = "Verona is home to two feuding noble houses, the Montagues and the Capulets. In response to the constant brawling between members of these families, the Prince of Verona has issued an edict that will impose a death sentence on anyone caught dueling. Against this backdrop, young Romeo of the house of Montague has recently been infatuated with Rosaline, a niece of Capulet. Rosaline is quickly forgotten, however, when Romeo and his friends disguise themselves and slip into a masque ball at Capulet's house. During the festivities, Romeo catches his first glimpse of Juliet, Capulet's daughter. In one of Shakespeare's most memorable scenes, Romeo steals into the garden and professes his love to Juliet, who stands above on her balcony. The two young lovers, with the aid of Friar Laurence, make plans to be married in secret.\n Tybalt, Juliet's cousin, later discovers that Romeo has attended the ball, and he sets out to teach the young Montague a lesson at the point of his sword. Romeo is challenged by Tybalt, but tries to avoid a duel between them since he is now married to Juliet (making Tybalt a kinsman). Mercutio, Romeo's best friend, takes up Tybalt's challenge and is killed in the ensuing fight. Enraged, Romeo slays Tybalt in turn. As a result of this bloodshed, the Prince proclaims that Romeo is to be banished from Verona for his actions. Romeo has time to consummate the marriage and bid farewell to Juliet, though he hopes to be reunited with her once the Capulets learn that they are man and wife. \n The Capulets, meanwhile, press for Juliet to marry Paris, a cousin to the Prince. Juliet, relying again on Friar Laurence, devises a desperate plan to avoid her parent's wishes. She obtains a drug that will make her seem dead for forty-two hours; while she is in this state, Friar Laurence will send word to Romeo of the situation so that he can rescue her from her tomb. Unfortunately, fate will not be so kind; the letter from Friar Laurence is delayed. Romeo instead hears second-hand news that Juliet has died. Grief-stricken, Romeo purchases poison and hastens to Juliet's tomb to die at her side. Meanwhile, Friar Laurence has discovered to his horror that his letter did not arrive, and he means to take Juliet away until he can set things aright."
                  , Title = "Romeo and Juliet", TimesViewed = 34 },
                new Book { Id = 4, AuthorId = 2, BookImg = "http://ecx.images-amazon.com/images/I/51yChJoybWL._SY344_BO1,204,203,200_.jpg", ISBN = 3496, PubDate = Convert.ToDateTime("1/1/1500"), Summary = "Hamlet, Prince of Denmark, has multiple woes. The ghost of his father haunts Elsinore; his uncle, Claudius, has married Queen Gertrude, his mother, and assumed the throne; and Fortinbras of Norway threatens Denmark with an invading army. When Hamlet meets the ghost, his dead father reveals that Claudius poisoned him—and the ghost demands that Hamlet exact revenge. In order to carry this out, Hamlet feigns madness; as part of his insanity, he scorns the affections of Ophelia, daughter of Polonius, to whom he had made romantic overtures. Polonius grows concerned over the apparent insanity that has beset Hamlet and reveals it to the King and Queen. Meanwhile, Hamlet struggles to convince himself that Claudius is the murderer of his father, and in an attempt to \"catch the king's conscience,\" Hamlet convinces a traveling troupe of actors to perform a play in which the action closely resembles the events related to him by the ghost.\n While Hamlet, judging the reaction of Claudius, is convinced of the new king's guilt, he can't bring himself to slay him outright. Instead, Hamlet rebukes Gertrude with the news that she is sleeping with the killer of her husband. Unfortunately, Polonius—who is hidden behind a tapestry in the Queen's chamber, eavesdropping—panics and cries for help; Hamlet stabs him, thinking it is Claudius. Of course, when this news is given to Claudius, the King sends Hamlet to England with the ostensible purpose of securing Hamlet's safety and the recovery of his senses. Rosencrantz and Guildenstern, two childhood friends of Hamlet's who are now little more than spies for Claudius, are to accompany him. The trick is that Hamlet will bear a letter to the King of England in which Claudius asks England to sentence Hamlet to death. \nIn the midst of these events, Ophelia loses her own sanity; she is driven to madness by Hamlet's condition and the death of Polonius. Laertes, her brother, returns to Elsinore from his studies and vows his vengeance upon Hamlet for what the prince has done to his family. News is brought that Hamlet has returned to Denmark, much to the surprise of Claudius, and that Ophelia has drowned herself in a river. Claudius now plots with Laertes to kill Hamlet upon his return to Elsinore. Meanwhile, Hamlet meets Horatio, his best friend, and tells how he altered the letter so that the execution order was for Rosencrantz and Guildenstern instead of him. At the end of Hamlet's tale, Ophelia's funeral procession enters, and Laertes and Hamlet confront one another. Laertes challenges Hamlet to a duel.\n This is all part of Claudius's plot; instead of dull blades, Laertes will select a sharp one. In addition, Laertes is to poison the tip of his blade so that a wound will kill the prince. And, just in case the previous measures are not enough, Claudius will keep a poisoned chalice from which Hamlet will drink. The plan goes awry from the beginning; Laertes is unable to wound Hamlet during the first pass. Between rounds, Gertrude raises a toast to Hamlet with the poisoned chalice. Then, in the heat of the duel, Laertes manages to wound Hamlet but loses the poisoned rapier to him, and Laertes himself is poisoned as well. Gertrude swoons to her death; Laertes falls and reveals the plot against Hamlet, telling him he has \"not a half-hour's life\" in him. Enraged, Hamlet stabs Claudius with the poisoned foil, then makes him drink from the chalice that slew Gertrude. This done, Hamlet collapses and dies in Horatio's arms as Fortinbras enters the castle. Fortinbras is left to rule Denmark, as the entire royal family is dead, and he bids his men give Hamlet and the rest a proper funeral.", Title = "Hamlet", TimesViewed = 44 },
                //Seeder begins here
                new Book { Id = 5, AuthorId = 6, BookImg = "http://obxentertainment.com/wp-content/uploads/2015/04/The-Wright-Brothers-by-David-McCullough.jpg", ISBN = 1142, PubDate = Convert.ToDateTime("6/7/1969"), Summary = "Two-time winner of the Pulitzer Prize David McCullough tells the dramatic story-behind-the-story about the courageous brothers who taught the world how to fly: Wilbur and Orville Wright. \n On a winter day in 1903, in the Outer Banks of North Carolina, two unknown brothers from Ohio changed history. But it would take the world some time to believe what had happened: the age of flight had begun, with the first heavier-than-air, powered machine carrying a pilot. \n Who were these men and how was it that they achieved what they did? \n David McCullough, two-time winner of the Pulitzer Prize, tells the surprising, profoundly American story of Wilbur and Orville Wright. \n Far more than a couple of unschooled Dayton bicycle mechanics who happened to hit on success, they were men of exceptional courage and determination, and of far-ranging intellectual interests and ceaseless curiosity, much of which they attributed to their upbringing. The house they lived in had no electricity or indoor plumbing, but there were books aplenty, supplied mainly by their preacher father, and they never stopped reading.", Title = "The Wright Brothers", TimesViewed = 786 },
                new Book { Id = 6, AuthorId = 5, BookImg = "http://pixel.nymag.com/imgs/daily/vulture/2014/12/15/15-judy-blume-book.w529.h352.2x.jpg", ISBN = 8945, PubDate = Convert.ToDateTime("4/7/2014"), Summary = "In 1987, Miri Ammerman returns to her hometown of Elizabeth, New Jersey, to attend a commemoration of the worst year of her life. Thirty-five years earlier, when Miri was fifteen, and in love for the first time, a succession of airplanes fell from the sky, leaving a community reeling. Against this backdrop of actual events that Blume experienced in the early 1950s, when airline travel was new and exciting and everyone dreamed of going somewhere, she paints a vivid portrait of a particular time and place—Nat King Cole singing “Unforgettable,” Elizabeth Taylor haircuts, young (and not-so-young) love, explosive friendships, A-bomb hysteria, rumors of Communist threat. And a young journalist who makes his name reporting tragedy. Through it all, one generation reminds another that life goes on.\n In the Unlikely Event is vintage Judy Blume, with all the hallmarks of Judy Blume’s unparalleled storytelling, and full of memorable characters who cope with loss, remember the good times and, finally, wonder at the joy that keeps them going.\n Early reviewers have already weighed in: “Like many family stories, this one is not without its life-changing secrets and surprises. There is no surprise that the book is smoothly written, and its story compelling. The setting—the early 1950s—is especially well realized through period references and incidents.” —Booklist (starred review) and “In Blume’s latest adult novel . . . young and old alike must learn to come to terms with technological disaster and social change. Her novel is characteristically accessible, frequently charming and always deeply human.” —Publishers Weekly", Title = "In The Unlikely Event", TimesViewed = 432 },
                new Book { Id = 7, AuthorId = 5, BookImg = "http://cdn.sheknows.com/articles/2013/10/allParenting/Judy_Blume_covers/Tiger_Eyes.jpg", ISBN = 6678, PubDate = Convert.ToDateTime("1/1/1597"), Summary = "What does it take to recover from tragedy? This masterful Judy Blume novel has a fresh new look.\n Davey Wexler has never felt so alone. Her father has just been killed—shot in a holdup at the 7-Eleven near their home. And now her mother has transplanted her and her little brother, Jason, to Los Alamos, New Mexico, to stay with family and recover.\n But Davey is withdrawn, full of rage and fear and loneliness. Then one day, while exploring a canyon, she meets an older boy who calls himself Wolf. Wolf is the only one who understands her—the only one who can read her sad eyes. And he is the one who helps her realize that she must find a way to move forward with her life.\n Davey is one of Judy Blume’s most hauntingly true human beings, capturing the deep ways a person can change that can’t be seen—only felt. Her story has been felt, deeply, by readers for decades.", Title = "Tiger Eyes", TimesViewed = 34 },
                new Book { Id = 8, AuthorId = 2, BookImg = "http://ecx.images-amazon.com/images/I/51yChJoybWL._SY344_BO1,204,203,200_.jpg", ISBN = 3496, PubDate = Convert.ToDateTime("1/1/1500"), Summary = "How to be a man", Title = "Hamlet", TimesViewed = 44 },
               new Book { Id = 9, AuthorId = 5, BookImg = "http://blogs.babycenter.com/wp-content/gallery/judy-blume-books/judy.jpg", ISBN = 5243, PubDate = Convert.ToDateTime("6/7/1969"), Summary = "Margaret shares her secrets and her spirituality in this iconic Judy Blume novel, beloved by millions, that now has a fresh new look.\n Margaret Simon, almost twelve, likes long hair, tuna fish, the smell of rain, and things that are pink. She’s just moved from New York City to Farbook, New Jersey, and is anxious to fit in with her new friends—Nancy, Gretchen, and Janie. When they form a secret club to talk about private subjects like boys, bras, and getting their first periods, Margaret is happy to belong.\n But none of them can believe Margaret doesn’t have religion, and that she isn’t going to the Y or the Jewish Community Center. What they don’t know is Margaret has her own very special relationship with God. She can talk to God about everything—family, friends, even Moose Freed, her secret crush. \n Margaret is funny and real, and her thoughts and feelings are oh-so-relatable—you’ll feel like she’s talking right to you, sharing her secrets with a friend.", Title = "Are You There God? It's me, Margaret", TimesViewed = 786 },
                new Book { Id = 10, AuthorId = 1, BookImg = "http://justforthefunzies.com/wp-content/uploads/2013/09/ron-swanson.jpg", ISBN = 4598, PubDate = Convert.ToDateTime("4/7/2014"), Summary = "How to be a man", Title = "Manhood", TimesViewed = 432 },
                new Book { Id = 11, AuthorId = 2, BookImg = "http://d28hgpri8am2if.cloudfront.net/book_images/cvr9781451621709_9781451621709_hr.jpg", ISBN = 4725, PubDate = Convert.ToDateTime("1/1/1597"), Summary = "How to be a man", Title = "Romeo and Juliet", TimesViewed = 34 },
                new Book { Id = 12, AuthorId = 4, BookImg = "http://ecx.images-amazon.com/images/I/51jhJmZPqrL._SY344_BO1,204,203,200_.jpg", ISBN = 9678, PubDate = Convert.ToDateTime("1/1/1500"), Summary = "On September 1, 1894, two forest fires converged on the town of Hinckley, Minnesota, trapping more than two thousand people. The fire created its own weather, including hurricane-strength winds, bubbles of plasma-like glowing gas, and 200-foot-tall flames. As temperatures reached 1,600 degrees Fahrenheit, the firestorm knocked down buildings and carried flaming debris high into the sky. Two trains—one with every single car on fire—became the only means of escape. In all, more than four hundred people would die, leading to a revolution in forestry management and the birth of federal agencies that monitor and fight wildfires. \n A spellbinding account of danger, devastation, and courage, Under a Flaming Sky reveals the dramatic, minute-by-minute story of the tragedy and brings into focus the ordinary citizens whose lives it irrevocably marked.", Title = "Under a Flaming Sky", TimesViewed = 44 },
               new Book { Id = 13, AuthorId = 4, BookImg = "http://d.gr-assets.com/books/1434499342l/6033525.jpg", ISBN = 4467, PubDate = Convert.ToDateTime("6/7/1969"), Summary = "In April of 1846, twenty-one-year-old Sarah Graves, intent on a better future, set out west from Illinois with her new husband, her parents, and eight siblings. Seven months later, after joining a party of emigrants led by George Donner, they reached the Sierra Nevada Mountains as the first heavy snows of the season closed the pass ahead of them. In early December, starving and desperate, Sarah and fourteen others set out for California on snowshoes and, over the next thirty-two days, endured almost unfathomable hardships and horrors.\n In this gripping narrative, Daniel James Brown sheds new light on one of the most infamous events in American history. Following every painful footstep of Sarah's journey with the Donner Party, Brown produces a tale both spellbinding and richly informative.", Title = "The Indifferent Stars Above", TimesViewed = 786 },
                new Book { Id = 14, AuthorId = 3, BookImg = "http://s3images.coroflot.com/user_files/individual_files/226546_kQwETHUK7recHY7nPRooBm2fG.jpg", ISBN = 8847, PubDate = Convert.ToDateTime("4/7/2014"), Summary = "It is a 1986 horror novel by American author Stephen King. The story follows the exploits of seven children as they are terrorized by the eponymous being, which exploits the fears and phobias of its victims in order to disguise itself while hunting its prey.\"It\" primarily appears in the form of a clown in order to attract its preferred prey of young children. The novel is told through narratives alternating between two time periods, and is largely told in the third-person omniscient mode. It deals with themes that eventually became King staples: the power of memory, childhood trauma, and the ugliness lurking behind a façade of traditional small-town values. The novel won the British Fantasy Award in 1987, and received nominations for the Locus and World Fantasy Awards that same year.", Title = "It", TimesViewed = 432 },
                new Book { Id = 15, AuthorId = 3, BookImg = "http://d28hgpri8am2if.cloudfront.net/book_images/cvr9781451621709_9781451621709_hr.jpg", ISBN = 2442, PubDate = Convert.ToDateTime("1/1/1597"), Summary = "WINNER OF THE 2015 EDGAR AWARD FOR BEST NOVEL In a mega-stakes, high-suspense race against time, three of the most unlikely and winning heroes Stephen King has ever created try to stop a lone killer from blowing up thousands. \n In the frigid pre-dawn hours, in a distressed Midwestern city, hundreds of desperate unemployed folks are lined up for a spot at a job fair. Without warning, a lone driver plows through the crowd in a stolen Mercedes, running over the innocent, backing up, and charging again. Eight people are killed; fifteen are wounded. The killer escapes. \n In another part of town, months later, a retired cop named Bill Hodges is still haunted by the unsolved crime. When he gets a crazed letter from someone who self-identifies as the “perk” and threatens an even more diabolical attack, Hodges wakes up from his depressed and vacant retirement, hell-bent on preventing another tragedy. \n Brady Hartsfield lives with his alcoholic mother in the house where he was born. He loved the feel of death under the wheels of the Mercedes, and he wants that rush again. Only Bill Hodges, with a couple of highly unlikely allies, can apprehend the killer before he strikes again. And they have no time to lose, because Brady’s next mission, if it succeeds, will kill or maim thousands. \n Brady Hartsfield lives with his alcoholic mother in the house where he was born. He loved the feel of death under the wheels of the Mercedes, and he wants that rush again. Only Bill Hodges, with a couple of highly unlikely allies, can apprehend the killer before he strikes again. And they have no time to lose, because Brady’s next mission, if it succeeds, will kill or maim thousands.                                                                      ", Title = "Mr. Mercedes", TimesViewed = 34 },
                new Book { Id = 16, AuthorId = 2, BookImg = "http://ecx.images-amazon.com/images/I/51yChJoybWL._SY344_BO1,204,203,200_.jpg", ISBN = 7823, PubDate = Convert.ToDateTime("1/1/1500"), Summary = "Hamlet, Prince of Denmark, has multiple woes. The ghost of his father haunts Elsinore; his uncle, Claudius, has married Queen Gertrude, his mother, and assumed the throne; and Fortinbras of Norway threatens Denmark with an invading army. When Hamlet meets the ghost, his dead father reveals that Claudius poisoned him—and the ghost demands that Hamlet exact revenge. In order to carry this out, Hamlet feigns madness; as part of his insanity, he scorns the affections of Ophelia, daughter of Polonius, to whom he had made romantic overtures. Polonius grows concerned over the apparent insanity that has beset Hamlet and reveals it to the King and Queen. Meanwhile, Hamlet struggles to convince himself that Claudius is the murderer of his father, and in an attempt to \"catch the king's conscience,\" Hamlet convinces a traveling troupe of actors to perform a play in which the action closely resembles the events related to him by the ghost.\n While Hamlet, judging the reaction of Claudius, is convinced of the new king's guilt, he can't bring himself to slay him outright. Instead, Hamlet rebukes Gertrude with the news that she is sleeping with the killer of her husband. Unfortunately, Polonius—who is hidden behind a tapestry in the Queen's chamber, eavesdropping—panics and cries for help; Hamlet stabs him, thinking it is Claudius. Of course, when this news is given to Claudius, the King sends Hamlet to England with the ostensible purpose of securing Hamlet's safety and the recovery of his senses. Rosencrantz and Guildenstern, two childhood friends of Hamlet's who are now little more than spies for Claudius, are to accompany him. The trick is that Hamlet will bear a letter to the King of England in which Claudius asks England to sentence Hamlet to death. \nIn the midst of these events, Ophelia loses her own sanity; she is driven to madness by Hamlet's condition and the death of Polonius. Laertes, her brother, returns to Elsinore from his studies and vows his vengeance upon Hamlet for what the prince has done to his family. News is brought that Hamlet has returned to Denmark, much to the surprise of Claudius, and that Ophelia has drowned herself in a river. Claudius now plots with Laertes to kill Hamlet upon his return to Elsinore. Meanwhile, Hamlet meets Horatio, his best friend, and tells how he altered the letter so that the execution order was for Rosencrantz and Guildenstern instead of him. At the end of Hamlet's tale, Ophelia's funeral procession enters, and Laertes and Hamlet confront one another. Laertes challenges Hamlet to a duel.\n This is all part of Claudius's plot; instead of dull blades, Laertes will select a sharp one. In addition, Laertes is to poison the tip of his blade so that a wound will kill the prince. And, just in case the previous measures are not enough, Claudius will keep a poisoned chalice from which Hamlet will drink. The plan goes awry from the beginning; Laertes is unable to wound Hamlet during the first pass. Between rounds, Gertrude raises a toast to Hamlet with the poisoned chalice. Then, in the heat of the duel, Laertes manages to wound Hamlet but loses the poisoned rapier to him, and Laertes himself is poisoned as well. Gertrude swoons to her death; Laertes falls and reveals the plot against Hamlet, telling him he has \"not a half-hour's life\" in him. Enraged, Hamlet stabs Claudius with the poisoned foil, then makes him drink from the chalice that slew Gertrude. This done, Hamlet collapses and dies in Horatio's arms as Fortinbras enters the castle. Fortinbras is left to rule Denmark, as the entire royal family is dead, and he bids his men give Hamlet and the rest a proper funeral.", Title = "Hamlet", TimesViewed = 44 }
                );
        }

        private static void SeedTags(ApplicationDbContext db)
        {
            db.Tags.AddOrUpdate(x => x.Id,
                new Tag { Id = 1, Description = "Action" },
                new Tag { Id = 2, Description = "Sci-Fi" },
                new Tag { Id = 3, Description = "Romance" },
                new Tag { Id = 4, Description = "Horror" },
                new Tag { Id = 5, Description = "Self-Help" },
                new Tag { Id = 6, Description = "Fiction" },
                new Tag { Id = 7, Description = "History" },
                new Tag { Id = 8, Description = "Science" },
                new Tag { Id = 9, Description = "Non-Fiction" }
                );
        }

        private static void SeedAuthorTags(ApplicationDbContext db)
        {
            db.Author_Tags.AddOrUpdate(x => x.Id,
                new Author_Tags { Id = 1, AuthorId = 1, TagId = 1 },
                new Author_Tags { Id = 2, AuthorId = 2, TagId = 2 },
                new Author_Tags { Id = 3, AuthorId = 3, TagId = 3 },
                new Author_Tags { Id = 4, AuthorId = 4, TagId = 4 },
                new Author_Tags { Id = 5, AuthorId = 5, TagId = 5 },
                new Author_Tags { Id = 6, AuthorId = 6, TagId = 6 },
                new Author_Tags { Id = 7, AuthorId = 1, TagId = 7 },
                new Author_Tags { Id = 8, AuthorId = 2, TagId = 8 },
                new Author_Tags { Id = 9, AuthorId = 3, TagId = 9 },
                new Author_Tags { Id = 10, AuthorId = 4, TagId = 1 },
                new Author_Tags { Id = 11, AuthorId = 5, TagId = 2 },
                new Author_Tags { Id = 12, AuthorId = 6, TagId = 3 },
                new Author_Tags { Id = 13, AuthorId = 1, TagId = 4 },
                new Author_Tags { Id = 14, AuthorId = 1, TagId = 5 },
                new Author_Tags { Id = 15, AuthorId = 3, TagId = 6 },
                new Author_Tags { Id = 16, AuthorId = 6, TagId = 7 }
                );
        }

        private static void SeedBookTags(ApplicationDbContext db)
        {
            db.Book_Tags.AddOrUpdate(x => x.Id,
                new Book_Tags { Id = 1, BookId = 1, TagId = 1 },
                new Book_Tags { Id = 2, BookId = 2, TagId = 2 },
                new Book_Tags { Id = 3, BookId = 3, TagId = 3 },
                new Book_Tags { Id = 4, BookId = 4, TagId = 4 },
                new Book_Tags { Id = 5, BookId = 5, TagId = 5 },
                new Book_Tags { Id = 6, BookId = 6, TagId = 6 },
                new Book_Tags { Id = 7, BookId = 7, TagId = 7 },
                new Book_Tags { Id = 8, BookId = 8, TagId = 8 },
                new Book_Tags { Id = 9, BookId = 9, TagId = 9 },
                new Book_Tags { Id = 10, BookId = 10, TagId = 1 },
                new Book_Tags { Id = 11, BookId = 11, TagId = 2 },
                new Book_Tags { Id = 12, BookId = 12, TagId = 3 },
                new Book_Tags { Id = 13, BookId = 13, TagId = 4 },
                new Book_Tags { Id = 14, BookId = 14, TagId = 5 },
                new Book_Tags { Id = 15, BookId = 15, TagId = 6 },
                new Book_Tags { Id = 16, BookId = 16, TagId = 7 },
                new Book_Tags { Id = 17, BookId = 1, TagId = 8 },
                new Book_Tags { Id = 18, BookId = 2, TagId = 9 },
                new Book_Tags { Id = 19, BookId = 3, TagId = 1 },
                new Book_Tags { Id = 20, BookId = 4, TagId = 2 },
                new Book_Tags { Id = 21, BookId = 5, TagId = 3 },
                new Book_Tags { Id = 22, BookId = 6, TagId = 4 },
                new Book_Tags { Id = 23, BookId = 7, TagId = 5 },
                new Book_Tags { Id = 24, BookId = 8, TagId = 6 },
                new Book_Tags { Id = 25, BookId = 9, TagId = 7 },
                new Book_Tags { Id = 26, BookId = 10, TagId = 8 },
                new Book_Tags { Id = 27, BookId = 11, TagId = 9 },
                new Book_Tags { Id = 28, BookId = 12, TagId = 1 },
                new Book_Tags { Id = 29, BookId = 13, TagId = 2 },
                new Book_Tags { Id = 30, BookId = 14, TagId = 3 },
                new Book_Tags { Id = 31, BookId = 15, TagId = 4 },
                new Book_Tags { Id = 32, BookId = 16, TagId = 5 },
                new Book_Tags { Id = 33, BookId = 1, TagId = 6 },
                new Book_Tags { Id = 34, BookId = 4, TagId = 7 },
                new Book_Tags { Id = 35, BookId = 4, TagId = 8 }
                );
        }

        private static void SeedRatings(ApplicationDbContext db)
        {
            db.Ratings.AddOrUpdate(
                r => r.Id,
                new Rating { Id = 1, BookId = 1, BookRating = 5, Comment = "The author told me to give a rating. He paid an extra $25 for a five star rating.", UserId = Test },
                new Rating { Id = 2, BookId = 2, BookRating = 3.5, Comment = "English style is archaic.", UserId = Test },
                new Rating { Id = 4, BookId = 5, BookRating = 4.5, Comment = "Very touching. I love this book and bought everyone in my family a copy for Christmas.", UserId = Test },
                new Rating { Id = 5, BookId = 5, BookRating = 2.5, Comment = null, UserId = Test },
                new Rating { Id = 6, BookId = 4, BookRating = 4.5, Comment = "Historical facts check out. In fact, I use this book as a reference for most of my historical based conversations. It's really suspenseful and made me jump at least three times, which doesn't really happen often.", UserId = Test },
                new Rating { Id = 7, BookId = 5, BookRating = 4.5, Comment = "Good story. I like to read, ya da ya da ya da. This is one of my all time favs. YOLO", UserId = Test },
                new Rating { Id = 8, BookId = 6, BookRating = 3.5, Comment = "Read leisurely. Feed seziurly. Bead measurely. Lead megerly. seed littly.", UserId = Test },
                new Rating { Id = 9, BookId = 10, BookRating = 3.5, Comment = null, UserId = Ralph },
                new Rating { Id = 10, BookId = 11, BookRating = 5, Comment = "A classic. I think that this book should be taught in every school and probably in university also. There's no doubt about it. This book is an absolutely classic.", UserId = Ralph },
                new Rating { Id = 11, BookId = 12, BookRating = 5, Comment = null, UserId = Ralph },
                new Rating { Id = 12, BookId = 13, BookRating = 5, Comment = "I would recommend this book to everyone, and I do. If you don't you should, because it's that good.", UserId = Ralph },
                new Rating { Id = 13, BookId = 15, BookRating = 5, Comment = "Riveting, but scary. So scary that I had to close the door, and right after I closed the do my cat popped out of no where. I was one of the scariest things ever.", UserId = Ralph },
                new Rating { Id = 14, BookId = 16, BookRating = 5, Comment = null, UserId = Ralph },
                //more dummy data
                new Rating { Id = 15, BookId = 1, BookRating = 2, Comment = "The author told me to give a rating, but he ran out of money after the first guy, so I gave him a rating of 1.", UserId = Ralph },
                new Rating { Id = 16, BookId = 2, BookRating = 5, Comment = "English style is archaic.", UserId = Ralph },
                new Rating { Id = 17, BookId = 3, BookRating = 1, Comment = "Started strong, and kept my attention til the end.", UserId = Sally },
                new Rating { Id = 18, BookId = 5, BookRating = .5, Comment = "Very touching.", UserId = Sally },
                new Rating { Id = 19, BookId = 5, BookRating = 3, Comment = null, UserId = Sally },
                new Rating { Id = 20, BookId = 4, BookRating = 4, Comment = "Historical facts check out.", UserId = Sally },
                new Rating { Id = 21, BookId = 5, BookRating = 2, Comment = "Good story.", UserId = Sally },
                new Rating { Id = 22, BookId = 6, BookRating = 5, Comment = "Read leisurely.", UserId = Sally },
                new Rating { Id = 23, BookId = 10, BookRating = 5, Comment = null, UserId = Joe },
                new Rating { Id = 24, BookId = 11, BookRating = 2, Comment = "A classic, like the other guy said but seriously....so classic.", UserId = Joe },
                new Rating { Id = 25, BookId = 12, BookRating = 2, Comment = null, UserId = Joe },
                new Rating { Id = 26, BookId = 13, BookRating = 2, Comment = "I would recommend this book.", UserId = Joe },
                new Rating { Id = 27, BookId = 15, BookRating = 2, Comment = "Riveting, but scary.", UserId = Joe },
                new Rating { Id = 28, BookId = 16, BookRating = 2, Comment = null, UserId = Joe },
                new Rating { Id = 29, BookId = 1, BookRating = 1, Comment = "The author told me to give a rating.", UserId = Vanessa },
                new Rating { Id = 30, BookId = 2, BookRating = 2, Comment = "English style is archaic.", UserId = Vanessa },
                new Rating { Id = 31, BookId = 3, BookRating = 3, Comment = "Started strong, and kept my attention til the end.", UserId = Vanessa },
                new Rating { Id = 32, BookId = 5, BookRating = 4, Comment = "Very touching.", UserId = Vanessa },
                new Rating { Id = 33, BookId = 5, BookRating = 5, Comment = null, UserId = Vanessa },
                new Rating { Id = 34, BookId = 4, BookRating = 1, Comment = "Historical facts check out.", UserId = Vanessa },
                new Rating { Id = 35, BookId = 5, BookRating = 2, Comment = "Good story.", UserId = Jimmy },
                new Rating { Id = 36, BookId = 6, BookRating = 3, Comment = "Read leisurely.", UserId = Jimmy },
                new Rating { Id = 38, BookId = 11, BookRating = 5, Comment = "A classic.", UserId = Jimmy },
                new Rating { Id = 39, BookId = 12, BookRating = 1, Comment = null, UserId = Jimmy },
                new Rating { Id = 40, BookId = 13, BookRating = 2, Comment = "I would recommend this book.", UserId = Jimmy },
                new Rating { Id = 41, BookId = 15, BookRating = 3, Comment = "Riveting, but scary.", UserId = Jimmy },
                new Rating { Id = 14, BookId = 16, BookRating = 4, Comment = null, UserId = Jimmy }

            );
        }
    }
}